package meijuli.com.join51.business.activity;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v7.widget.Toolbar;
import android.text.TextUtils;
import android.view.View;
import android.widget.TextView;

import meijuli.com.join51.business.R;
import meijuli.com.join51.business.fragment.AttestCompanyFragment;
import meijuli.com.join51.business.fragment.AttestPersonFragment;
import meijuli.com.join51.business.fragment.AttestShopFragment;
import meijuli.com.join51.business.fragment.BindBankFragment;

/**
 * 联盟商家认证页面
 *
 * @author wenqin 2017-04-14 13:55
 */

public class CertificationActivity extends BaseActivity {
    public static final String KEY_STATUS = "status";
    private FragmentManager fm;
    TextView mToolbarTitle;
    Toolbar mToolbar;

    public static void start(Activity activity, int status) {
        Intent intent = new Intent(activity,CertificationActivity.class);
        intent.putExtra(KEY_STATUS,status);
        activity.startActivity(intent);
    }

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_base_fragment);
        mToolbarTitle = findViewById(R.id.toolbar_title);
        mToolbar = findViewById(R.id.toolbar);
        fm = getSupportFragmentManager();

        initToolBar();

        if (savedInstanceState == null) {
            int status = getIntent().getIntExtra(KEY_STATUS,0);
            Fragment fragment;
            switch (status) {
                case 1:
                    fragment = new AttestPersonFragment();
                    break;
                case 2:
                    fragment = new AttestShopFragment();
                    break;
                case 3:
                    fragment = new BindBankFragment();
                    break;
                default:
                    fragment = new AttestCompanyFragment();
                    break;
            }
            addFragment(fragment);
        }
    }

    private void initToolBar() {
        mToolbar.setTitle("");
        mToolbarTitle.setText("商家认证");
        mToolbar.setNavigationIcon(R.mipmap.icon_back_white);
        mToolbar.setNavigationOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (!fm.popBackStackImmediate()) {
                    finish();
                }
            }
        });
    }

    @Override
    public void onBackPressed() {
        if (!fm.popBackStackImmediate()) {
            super.onBackPressed();
        }
    }

    public void setToolbarTitle(String title) {
        if(!TextUtils.isEmpty(title)) {
            mToolbarTitle.setText(title);
        }
    }
}
